import { defineStore } from "pinia";
import { ref } from "vue";
export const useTokenStore = defineStore('token', () => {
    const token = ref('')
    const user = ref(null)
    const store = ref(null)
    const wholesaler = ref(null)
    const factory = ref(null)
    const shop = ref(null)

    const setToken = (newToken) => {
        token.value = newToken
    }
    const getToken = () => {
        return token.value
    }

    const setUser = (newUser) => {
        user.value = newUser
    }

    const setStore = (newStore) => {
        store.value = newStore
    }

    const setWholesaler = (newWholesaler) => {
        wholesaler.value = newWholesaler
    }

    const setFactory = (newFactory) => {
        factory.value = newFactory
    }

    const setShop = (newShop) => {
        shop.value = newShop

    }
    const updateUser = (updatedUser) => {
        user.value = {
            ...user.value,
            ...updatedUser
        }
    }

    const removeToken = () => {
        token.value = ''
    }

    const removeUser = () => {
        user.value = null
    }

    const removeStore = () => {
        store.value = null
    }

    const removeWholesaler = () => {
        wholesaler.value = null
    }

    const removeFactory = () => {
        factory.value = null
    }

    return {
        token, user, store, wholesaler, factory, setToken, setUser, setStore, setWholesaler, setFactory, updateUser, removeToken, removeUser, removeStore, removeWholesaler, removeFactory, setShop, getToken
    }
}, {
    persist: true
}
);